package com.hzc.springchan.bean.response;

import lombok.Data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * List数据返回体类
 * @author chen990627
 * @date 2022/10/06
 */
@Data
public class ListDataResponse<T> extends Response {

    private List<T> data;

    public static ListDataResponse newSuccess() {
        ListDataResponse response = new ListDataResponse();
        return (ListDataResponse) response.setSuccess();
    }

    public static ListDataResponse newSuccess(boolean dataInit) {
        ListDataResponse response = newSuccess();
        response.data = dataInit ? new ArrayList() : null;
        return response;
    }

    public static <T> ListDataResponse newSuccess(List<T> data) {
        Response response = ListDataResponse.newSuccess(false);
        ((ListDataResponse) response).setData(data);
        return (ListDataResponse) response;
    }

    public ListDataResponse put(T val) {
        this.data.add(val);
        return this;
    }

    public ListDataResponse putAll(Collection<T> list) {
        this.data.addAll(list);
        return this;
    }

    public ListDataResponse remove(T val) {
        this.data.remove(val);
        return this;
    }
}
